package com.qk.management.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.qk.common.util.PageResult;
import com.qk.entity.Dept;
import com.qk.management.mapper.DeptMapper;
import com.qk.management.service.DeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class DeptServiceImpl implements DeptService {
    @Autowired
    private DeptMapper deptMapper;

    @Override
    public void deleteById(Integer deptid) {
        deptMapper.deleteById(deptid);
    }

    @Override
    public List<Dept> listDept() {
        return deptMapper.listDept();
    }


    @Override
    public Dept selectById(Integer deptId) {
        return deptMapper.selectById(deptId);
    }

    @Override
    public void updateDept(Dept dept) {
        dept.setUpdateTime(LocalDateTime.now());
        deptMapper.updateDept(dept);
    }


    @Override
    public PageResult<Dept> page(String name, Integer status, Integer page, Integer pageSize) {

        PageHelper.startPage(page,pageSize);
        List<Dept> list = deptMapper.list(name,status);
        Page<Dept> rs=(Page<Dept>) list;
        return PageResult.<Dept>builder()
                .total((int)rs.getTotal())
                .rows(list)
                .build();

    }

    @Override
    public void addDept(Dept dept) {
        dept.setCreateTime(LocalDateTime.now());
        dept.setUpdateTime(LocalDateTime.now());
        deptMapper.insert(dept);
    }


}
